package com.mstore.service;

import java.util.ArrayList;
import java.util.List;

import com.mstore.dao.ScoreDao;
import com.mstore.pojo.Score;
/**
 * 
 *用户积分记录
 */
public class ScoreService {
	
	private ScoreDao scoreDao;
	/**
	 * 
	 *会员积分记录添加
	 */
	public void addScore(Score score){
		scoreDao.add(score);
	}
	
	/**
	 * 
	 * 对获取到的所有积分记录进行分页查询
	 */
	public List<Score> getScorePage(int index,Score score){
		List<Object>objects =  scoreDao.getScorePage(index, score);
		List<Score>scores = new ArrayList<Score>();
		for(Object object : objects){
			scores.add((Score)object);
		}
		return scores;
	}
	/**
	 * 
	 * 获取全部条数
	 */
	public int getScoreLine(Score score){
		return scoreDao.getScoreceLine(score);
	}

	/**
	 * 
	 *根据时间和member查询
	 */
	public Score getByTimeAndMember(Score score){
	return (Score) scoreDao.getByTimeAndMember(score);	
	}
	
	/**
	 * 查询会员在某企业的积分总数
	 */
	public Double getEaScore(Score score) {
		Object object = scoreDao.getEaScore(score);
		if (object != null) {
			return (Double)object;
		}
		return 0d;
	}
	
	/**
	 * 查询会员的积分总数
	 */
	public Double getTotleEaScore(Score score) {
		Object object = scoreDao.getTotleEaScore(score);
		if (object != null) {
			return (Double)object;
		}
		return 0d;
	}
	
	/**
	 * 根据memberId查询会员记录
	 */
	public List<Score> getScoreLogByMemberId(Long memberId) {
		List<Object>objects =  scoreDao.getScoreLogByMemberId(memberId);
		List<Score>scores = new ArrayList<Score>();
		for(Object object : objects){
			scores.add((Score)object);
		}
		return scores;
	}
	
	public void deleteById(Score score){
		scoreDao.deleteById(score);
	}
	public ScoreDao getScoreDao() {
		return scoreDao;
	}
	public void setScoreDao(ScoreDao scoreDao) {
		this.scoreDao = scoreDao;
	}
}
